package cn.edu.pku.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMethodMappingNamingStrategy;

import com.github.pagehelper.PageInfo;

import cn.edu.pku.constant.EnumStatus;
import cn.edu.pku.service.BorrowInfoService;
import cn.edu.pku.vo.BorrowInfoResponse;
import cn.edu.pku.vo.BorrowInfoResult;
import cn.edu.pku.vo.request.BorrowInfoRequest;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
public class BorrowInfoController {
	
	@Autowired
	BorrowInfoService borrowInfoService;
	
	
	@RequestMapping(value="getborrowerinfo",method=RequestMethod.GET)
	@ApiOperation(value="获取借阅信息数据接口", notes="传入pageNow,pageSize,author,status,bookName")
	public BorrowInfoResult getBorrowerInfo(Integer pageNum,Integer pageSize,BorrowInfoRequest borrowInfoRequest){
		log.info("获取借阅信息数据接口");
		BorrowInfoResult bir=new BorrowInfoResult();
		PageInfo<BorrowInfoResponse> borrowInfoList = borrowInfoService.getBorrowInfoList(pageNum, pageSize, borrowInfoRequest);
		bir.setData(borrowInfoList);
		bir.setStatus(EnumStatus.SUCCESS.getStatus());
		bir.setMsg(EnumStatus.SUCCESS.getDesc());
		return bir;
	}
	
	@RequestMapping(value="returnbook",method=RequestMethod.POST)
	@ApiOperation(value="归还图书接口", notes="归还图书的接口，传入参数:图书借阅管理的主键")
	public BorrowInfoResult returnBook(Integer id){
		BorrowInfoResult bir=new BorrowInfoResult();
		int returnBook = borrowInfoService.returnBook(id);
		if (returnBook>0) {
			bir.setStatus(EnumStatus.SUCCESS.getStatus());
			bir.setMsg(EnumStatus.SUCCESS.getDesc());
		} else {
			bir.setStatus(EnumStatus.FAILED.getStatus());
			bir.setMsg(EnumStatus.FAILED.getDesc());
		}
		return bir;
	}
	
	@RequestMapping(value="borrowerbook",method=RequestMethod.POST)
	@ApiOperation(value="借出图书接口", notes="借出图书的接口，传入参数:借阅人主键，图书主键")
	public BorrowInfoResult borrowerBook(Integer borrowerId,Integer bookId){
		BorrowInfoResult bir=new BorrowInfoResult();
		/*if (returnBook>0) {
			bir.setStatus(EnumStatus.SUCCESS.getStatus());
			bir.setMsg(EnumStatus.SUCCESS.getDesc());
		} else {
			bir.setStatus(EnumStatus.FAILED.getStatus());
			bir.setMsg(EnumStatus.FAILED.getDesc());
		}*/
		return bir;
	}
	
	
	
	
	
}
